# @FileName  : test1.py
# @Time      : 2025/3/27 14:13
# @Author    : LuZhaoHui
# @Software  : PyCharm

# pillow 应用
from aiTool.tool import *

IMAGEPATH = 'f:/data/image'

file_name = pathJoin(IMAGEPATH, 'haidianzhen/PH1.1-2-100/100-0000017A.jpg')
out_name = pathJoin(IMAGEPATH, 'haidianzhen/PH1.1-2-100/100-0000017AA.jpg')

ret = getImg1File(file_name)
print(ret)

# 编码 Base64 图像
# with open(file_name, "rb") as image_file:
#     image_base64 = base64.b64encode(image_file.read()).decode("utf-8")

# 解码 Base64 图像
# image_data = base64.b64decode(image_base64)
# img = Image.open(BytesIO(image_data))

img = Image.open(file_name)

max_width = 1920
max_height = 1200
if img.size[0] < img.size[1]:
    # 纵向图片
    max_height *= 2

img = imageResize(img, max_width, max_height)

if img.mode == 'RGB':
    img = img.convert('L')

img.show()

img.save(out_name,dpi=(300,300), format='JPEG', quality=100)


